/*
 * Copyright 2011 Subhabrata Ghosh <subho.ghosh at langene.net>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



package net.langene.nlp.model;

//~--- non-JDK imports --------------------------------------------------------

import net.langene.nlp.Context;
import net.langene.nlp.utils.ClassUtils;
import net.langene.nlp.utils.SentenceGrapher;
import net.langene.nlp.utils.Tokenizer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//~--- classes ----------------------------------------------------------------

/**
 *
 * @author Subhabrata Ghosh <subho.ghosh at langene.net>
 */
public class SentenceGraph {
    private static Logger	_logger = LoggerFactory.getLogger(SentenceGraph.class);

    //~--- fields -------------------------------------------------------------

    private SentenceGrapher	grapher;
    private SentenceGraphNode	root;
    private Sentence		sentence;
    private Tokenizer		tokenizer;

    //~--- constructors -------------------------------------------------------

    /**
     * Create a new instance of a Sentence Graph
     * 
     * @throws Exception
     */
    public SentenceGraph() throws Exception {
        String	lang = Context.get().getLanguage();

        tokenizer = (Tokenizer) ClassUtils.getImplInstance(lang, Tokenizer.class);
        tokenizer.setup();
        grapher = (SentenceGrapher) ClassUtils.getImplInstance(lang, SentenceGrapher.class);
        grapher.setup();
    }

    //~--- get methods --------------------------------------------------------

    /**
     * @return the root
     */
    public SentenceGraphNode getRoot() {
        return root;
    }

    //~--- set methods --------------------------------------------------------

    /**
     * @param root the root to set
     */
    public void setRoot(SentenceGraphNode root) {
        this.root = root;
    }

    //~--- get methods --------------------------------------------------------

    /**
     * @return the sentence
     */
    public Sentence getSentence() {
        return sentence;
    }

    //~--- methods ------------------------------------------------------------

    /**
     * Parse the specified sentence string into a Sentence Graph.
     * 
     * @param sentstr Sentence string.
     * @throws Exception
     */
    public void parse(String sentstr) throws Exception {
        sentence = tokenizer.tokenizer(sentstr);

        if (sentence == null) {
            throw new Exception("Error tokenizing sentence [" + sentstr + "]");
        }

        _logger.debug(sentence.toString());
        root = grapher.graph(sentence);
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
